package leetcode.editor.cn;

public class P441ArrangingCoins {
    public static void main(String[] args) {

        System.out.println(Solution.arrangeCoins(2));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
  static   class Solution {
        public static int arrangeCoins(int n) {
            long left = 1, right = n;
            while (left <= right) {
                long mid = left + (right - left) / 2;
                long total = mid * (mid + 1) / 2;
                if (total == n) {
                    return (int) mid;
                }
                if (total > n) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }

            return (int) right;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}